<template>
    <div class="bgimgseeker">
        <div class="login">
            <div>
            <h3>用户登录</h3>
            <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm">
                    <el-form-item prop="username" el-icon="el-icon-user">
                        <el-input placeholder="用户名" v-model="ruleForm.username" autocomplete="off" style="width: 300px;"></el-input>
                    </el-form-item>
                    <el-form-item prop="userpass" >
                        <el-input placeholder="密码" type="password" v-model="ruleForm.userpass"
                                  autocomplete="off" style="width: 300px"></el-input>
                    </el-form-item>
                <el-form-item>
                        <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
                        <el-button @click="resetForm('ruleForm')">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
    </div>
</template>

<script>
    export default {
        name: 'login',
        data() {
            return {
                list: [],
                activeIndex: '1',
                ruleForm: {
                    username: '',
                    userpass: '',

                },
                rules: {
                    username: [
                        {required: true, message: '请输入用户名', trigger: 'blur'},
                        {min: 6, max: 12, message: '长度在 6 到 12 个字符', trigger: 'blur'}
                    ],
                    userpass: [
                        {required: true, message: '请输入密码', trigger: 'blur'},
                        {min: 6, max: 12, message: '长度在 6 到 12 个字符', trigger: 'blur'}
                    ],
                }
            }
        },
        mounted() {
            this.addAnimation()
        },
        methods: {
            addAnimation() {
                let form = document.getElementsByClassName('registerForm')[0];
                form.classList.add('animated')
                form.classList.add('bounceInDown')
            },
            backIndex () {
                this.$router.push({name: 'index'})
            },
            toRegister () {
                this.$router.push({name: 'register'})
            },
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        alert('submit!');
                    } else {
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            },
            goBack() {
                this.$router.go(-1);
            },
            get() {
                this.axios.get('url').then(
                    (response) => {
                        console.log(response.data)
                        this.list = response.data.name;
                    }
                ).catch((error) => {
                    console.log(error)
                })

                this.axios.post('url', this.data).then(
                    (response) => {
                        console.log(response.data)
                        this.list = response.data.name;
                    }
                ).catch((error) => {
                    console.log(error)
                })
            }
        },
        // created() {
        //     this.get();
        // }
    }
</script>
<style>
    .login {
        display: flex;
        flex-direction: row;
        justify-content: center;
        background: #fff;
        border: 1px solid #ededed;
        margin-left: 55%;
        margin-top: 5%;
        width: 500px;
        box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.1);
        border-radius: 8px;
        position: relative;
    }
</style>
